package com.um.jdy.common.charge.service.impl;

import com.um.jdy.common.charge.entity.po.OrderEbPower;
import com.um.jdy.common.device.dao.FeeEbTimeDao;
import com.um.jdy.common.device.entity.po.FeeEbPower;
import com.um.jdy.common.device.entity.po.FeeEbTime;
import com.um.jdy.common.device.service.FeeEbTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.charge.service.OrderEbTimeService;
import com.um.jdy.common.charge.dao.OrderEbTimeDao;
import com.um.jdy.common.charge.entity.po.OrderEbTime;

import java.util.Date;
import java.util.List;

/**
 * 服务实现类：订单副本-两轮桩时段电价表
 */
@Service
@Transactional
@Slf4j
public class OrderEbTimeServiceImpl extends BaseEntityServiceImpl<OrderEbTimeDao,OrderEbTime>  implements OrderEbTimeService{

    @Autowired
    FeeEbTimeDao feeEbTimeDao;

    /**
     * 添加单车桩时段单价表
     * @param feeId
     * @param orderId
     */
    @Override
    public void addOrderTime(String feeId,String orderId){
        List<FeeEbTime> times = feeEbTimeDao.getRows(new String[]{"device_fee_id"},new Object[]{feeId},
                new String[]{"start_time"},new String[]{"asc"});
        for(FeeEbTime time : times){
            OrderEbTime item = new OrderEbTime();
            item.setChargeOrderId(orderId);
            item.setComId(time.getComId());
            item.setStartTime(time.getStartTime());
            item.setEndTime(time.getEndTime());
            item.setPrice(time.getPrice());
            item.setServiceFee(time.getServiceFee());
            item.setCreateTime(new Date());
            this.saveRow(item);
        }
    }
}
